﻿$('a.btn-active').live('click', function (e) {
    e.preventDefault();
    $.ajax({
        type: "GET",
        url: $(this).attr('href') + "&time=" + Math.random(),
        success: function (msg) {
            if (msg.result) {
                if (msg.active) {
                    $('a#id_button_active_' + msg.key + ' i').removeClass('font-icon-check-empty').addClass('font-icon-check');
                    var activehref = $('a#id_button_active_' + msg.key).attr('href');
                    activehref = activehref.replace('active=True', 'active=False');
                    $('a#id_button_active_' + msg.key).attr('href', activehref);
                    var options = $.parseJSON('{"text":"Đã được avtive!","layout":"topRight","type":"alert"}');
                    noty(options);
                } else {
                    $('a#id_button_active_' + msg.key + ' i').removeClass('font-icon-check').addClass('font-icon-check-empty');
                    var activehref = $('a#id_button_active_' + msg.key).attr('href');
                    activehref = activehref.replace('active=False', 'active=True');
                    $('a#id_button_active_' + msg.key).attr('href', activehref);
                    var options = $.parseJSON('{"text":"Đã ngừng avtive !","layout":"topRight","type":"alert"}');
                    noty(options);
                }
            }
            else {
                //alert(msg);
            }
        },
        error: function (msg) {
            //alert(msg);
        }
    });
});
